#include "RequestCodec.h";
#include "ResponseCodec.h"
using namespace std;

string encodeMsg(Codec* code) {
	return code->encodeMsg();
}

void* decodeMsg(Codec* code) {
	return code->decodeMsg();
}

void RequestInfo_test() {
	RequestInfo rqinfo;
	rqinfo.cmdType = 9;
	rqinfo.clientID = "1001";
	rqinfo.serverID = "2022";
	rqinfo.sign = "fuck the world";
	rqinfo.data = "ok";

	RequestCodec r1(&rqinfo);
	string s1 = encodeMsg(&r1);

	RequestCodec r2(s1);
	RequestMsg* rqmsg = (RequestMsg*)decodeMsg(&r2);
	cout << "rqmsg.cmdType:" << rqmsg->cmdtype()
		<< "\nrqmsg.clientID:" << rqmsg->clientid()
		<< "\nrqmsg.serverID:" << rqmsg->serverid()
		<< "\nrqmsg.sign:" << rqmsg->sign()
		<< "\nrqmsg.data:" << rqmsg->data() << endl;
}

void ResponseInfo_test() {
	ResponseInfo rpinfo;
	rpinfo.status= 9;
	rpinfo.seckeyid = 10;
	rpinfo.clientID = "1003";
	rpinfo.serverID = "2021";
	rpinfo.data = "no";

	ResponseCodec r1(&rpinfo);
	string s1 = encodeMsg(&r1);

	ResponseCodec r2(s1);
	ResponseMsg* rpmsg = (ResponseMsg*)decodeMsg(&r2);
	cout << "rpmsg.status:" << rpmsg->status()
		<< "\nrpmsg.seckeyid" << rpmsg->seckeyid()
		<< "\nrpmsg.clientID:" << rpmsg->clientid()
		<< "\nrpmsg.serverID:" << rpmsg->serverid()
		<< "\nrpmsg.data:" << rpmsg->data() << endl;
}

int main() {
	RequestInfo_test();
	cout << endl;
	ResponseInfo_test();
	return 0;

}